package com.mtsmda.chapter3.gcEx;

import java.util.Date;

public class GCEx {
	
	public static void main(String[] args) {
		
		Runtime runtime = Runtime.getRuntime();
		long beginFreeMemory = runtime.freeMemory();
		long endFreeMemory = 0;
		long afterGC = 0;
		System.out.println("availableProcessors - " + runtime.availableProcessors());
		System.out.println("maxMemory - " + runtime.maxMemory());
		System.out.println("freeMemory - " + runtime.freeMemory());
		System.out.println("totalMemory - " + runtime.totalMemory());
		
		int countObjDate = 1000000;
		while(countObjDate >= 0){
			countObjDate--;
			System.out.println(new Date());
		}
		System.out.println("freeMemory - " + runtime.freeMemory());
		System.out.println("totalMemory - " + runtime.totalMemory());
		endFreeMemory = runtime.freeMemory();
		runtime.gc();
		System.gc();
		afterGC = runtime.freeMemory();
		System.out.println("free memmory - " + (endFreeMemory - beginFreeMemory));
		System.out.println("begin free memmory - " + beginFreeMemory + "\n"
				+ "end free memmory - " + endFreeMemory + "\n"
						+ "after gc - " + afterGC);
	}
	
}